import java.util.*;
import java.sql.*;

class koneksi_database {
  public koneksi_database() {
  }

  public void load_DriverJDBC() {
    // Mencoba memanggil Driver JDBC
    try {
      Class.forName(getData("DriverJDBC"));
      // Gagal Memanggil Driver JDBC
    }
    catch (ClassNotFoundException cnfe) {
      System.out.println(cnfe);
    }
  }

  /**
   * Methode koneksiDatabase
   * Untuk melakukan koneksi dengan Database Server
   * Database Server = MySQL
   * getConection yang digunakan adalah getConnection(url)
   */
  public Connection koneksiDatabase() {
    // Mencoba melakukan koneksi dengan Database
    Connection koneksi = null;
    try {
      String url = getData("url");
      koneksi = DriverManager.getConnection(url);
    }
    catch (SQLException sqle) {
      System.out.println(sqle);
    }
    return koneksi;
  } // Akhir methode koneksiDatabase()

  public String getData(String key) {
    String value = null;
    try {
      value = getResourceBundle().getString(key);
    }
    catch (MissingResourceException e) {
      System.out.println(e + " : Couldn't find value for: " + key);
    }
    return value;
  }

  public ResourceBundle getResourceBundle() {
    ResourceBundle bundle = null;
    if (bundle == null) {
      bundle = ResourceBundle.getBundle("data_koneksiDatabase");
    }
    return bundle;
  }

}